package com.wanczy.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wanczy.pojo.UserTable;
import com.wanczy.service.UserSingleService;
import com.wanczy.service.impl.UserSingleServiceImpl;
import com.wanczy.util.StringToDate;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@WebServlet("/servlet/updateUserSingle")
public class UpdateUserSingleServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       try {
		PrintWriter out = response.getWriter();
		int userId= Integer.parseInt(request.getParameter("userId"));
		String userAccount = request.getParameter("userAccount");
		/*System.out.println(userAccount);*/
		int userSex = Integer.parseInt(request.getParameter("userSex"));
		String userEmail = request.getParameter("userEmail");
		int userAge = Integer.parseInt(request.getParameter("userAge"));
		String userPass = request.getParameter("userPass");
		//int userState = Integer.parseInt(request.getParameter("userState"));
		Date userBirthday = StringToDate.getDate(request.getParameter("userBirthday"));
		UserTable userTable = new UserTable(userId,userAccount,userSex,userEmail,userAge,userPass,1,userBirthday);
		UserSingleService service  = new UserSingleServiceImpl();
		boolean flag = service.doUpd(userTable);
		JSONArray jsonA = new JSONArray();
		JSONObject jsono = new JSONObject();
		jsono.put("flag", flag);
		jsonA.add(jsono);
		out.print(jsonA.toString());
		out.close();
	} catch (Exception e) {
		e.printStackTrace();
	}
}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
